package com.rimi.project.controller;

import com.rimi.project.bean.User;
import com.rimi.project.commos.ResponseData;
import com.rimi.project.commos.Status;
import com.rimi.project.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author chao
 * @date 2020/2/21
 */
@Controller
public class LoginController {

    @Autowired
    UserService userService;

    /** 映射首页 */
    @GetMapping("/")
    public String login() {
        return "login";
    }

    @GetMapping("/index")
    public String index() {
        return "index";
    }

    @GetMapping("/welcome")
    public String welcome() {
        return "welcome";
    }

    @ResponseBody
    @PostMapping(value = "/login",produces = "application/json")
    public ResponseData login(User user) {
        boolean login = userService.login(user);
        return login ? ResponseData.onSuccess() : ResponseData.onFailed(Status.LOGIN_NOT_MATCHED);
    }
}
